﻿
using SvGame.Logic;

namespace SvGame.Controller;

public partial class GameHandler
{
    /// <summary>
    /// 玩家移动
    /// </summary>
    /// <param name="pack"></param>
    public int C2GRoomGo(MyPackage pack)
    {
        pack.GetMsg(out C2GRoomGo req);
        var rsp = new G2CRoomGo();

        if (!pack.PackGetPlayer(out var player) || player is null)
        {
            return 0;
        }
        if (req.Dir == "c")
        {
            rsp.RoomInfo = player.Room.GetInfo();
            return 0;
        }
        if (player.IsBusy)
        {
            return player.MessageError(BusyMessage);
        }
        if (!player.Room.DictExit.TryGetValue(req.Dir, out var exit))
        {
            return player.MessageError("这个方向没有出路");
        }
        if (!GetRoom(exit.RoomUid, out var roomexit))
        {
            return player.MessageError("这个方向没有出路");
        }

        player.RoomGo(roomexit, req.Dir);

        return pack.Send(rsp);
    }
    /// <summary>
    /// 房间飞
    /// </summary>
    /// <param name="pack"></param>
    public int C2GRoomFly(MyPackage pack)
    {
        pack.GetMsg(out C2GRoomFly req);
        var rsp = new G2CRoomFly();

        if (!pack.PackGetPlayer(out var player) || player is null)
        {
            return 0;
        }
        if (player.IsBusy)
        {
            return player.MessageError(BusyMessage);
        }
        if (!ConfCity.TryGetValue(req.City, out var confcity))
        {
            return player.MessageError("错误的城市目标");
        }
        if (!GetRoom(confcity.FlyRoom, out var roomfly))
        {
            return player.MessageError("错误的房间目标");
        }

        var CfgFamily = player.CfgFamily;
        MessageVision(CfgFamily.FlyDesc1 + "#NOR#", player);
        player.RoomOut();

        player.RoomIn(roomfly);
        MessageVision(CfgFamily.FlyDesc2 + "#NOR#", player);

        player.RoomInfo();

        player.RoomInit();

        return pack.Send(rsp);
    }
}
